package cn.edu.ujn.springboot.controller;

import cn.edu.ujn.dao.Parkingrecord;
import cn.edu.ujn.dao.Vehicleinfo;
import cn.edu.ujn.service.IParkingrecordService;
import cn.edu.ujn.service.IVehicleinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class ParkingrecordController {

    @Autowired
    private IParkingrecordService parkingrecordService;
    @Autowired
    private IVehicleinfoService vehicleinfoService;

    @GetMapping("/parkingrecord")
    public List<Parkingrecord> parkingrecordList(Parkingrecord queryParams){
        System.out.println(queryParams);
        List<Parkingrecord> list = parkingrecordService.selectAll(queryParams);
        for(Parkingrecord i : list){
            System.out.println(i);
        }
        return list;
    }

    @PutMapping("/parkingrecord")
    public String parkingrecordEdit(@RequestBody Parkingrecord queryParam){
        System.out.println(queryParam);
        return parkingrecordService.updateByPrimaryKeySelective(queryParam) == 1 ? "success" : "fail";
    }

    @DeleteMapping("/parkingrecord/{id}")
    public String parkingrecordDelete(@PathVariable Integer id){
        return parkingrecordService.deleteByPrimaryKey(id) == 1 ? "success" : "fail";
    }

    @PostMapping("/parkingrecord")
    public String parkingrecordAdd(@RequestBody Parkingrecord queryParam){
        return parkingrecordService.insertSelective(queryParam) == 1 ? "success" : "fail";
    }

    @GetMapping("/getCar")
    public List<Vehicleinfo> getCar(){
        return vehicleinfoService.selectAll(null);
    }
}
